#include "settings.h"

#define DEFAULT_GIT_PORT 9418

Settings::Settings()
    : QSettings("gitserver.ini", QSettings::IniFormat)
{
}

Settings::~Settings()
{
}

//--------------------------------------------------------------------------------------------------

bool Settings::mustLaunchGitDaemonOnStartup() const
{
    return value("general/launchGitDaemonOnStartup", false).toBool();
}

//--------------------------------------------------------------------------------------------------

void Settings::setMustLaunchGitDaemonOnStartup(bool launch)
{
    return setValue("general/launchGitDaemonOnStartup", launch);
}

//--------------------------------------------------------------------------------------------------

QString Settings::gitExecutable() const
{
    return value("git/executable").toString();
}

//--------------------------------------------------------------------------------------------------

void Settings::setGitExecutable(const QString & path)
{
    setValue("git/executable", path);
}

//--------------------------------------------------------------------------------------------------

bool Settings::useDefaultGitPort() const
{
    return value("git/useDefaultGitPort", true).toBool();
}

//--------------------------------------------------------------------------------------------------

void Settings::setUseDefaultGitPort(bool state)
{
    return setValue("git/useDefaultGitPort", state);
}

//--------------------------------------------------------------------------------------------------

int Settings::gitPort() const
{
    return value("git/port", DEFAULT_GIT_PORT).toInt();
}

//--------------------------------------------------------------------------------------------------

void Settings::setGitPort(int port)
{
    setValue("git/port", port);
}

//--------------------------------------------------------------------------------------------------

QString Settings::gitBasePath() const
{
    return value("git/basepath").toString();
}

//--------------------------------------------------------------------------------------------------

void Settings::setGitBasePath(const QString & repo)
{
    setValue("git/basepath", repo);
}

//--------------------------------------------------------------------------------------------------

bool Settings::mustExportAll() const
{
    return value("git/exportall", true).toBool();
}

//--------------------------------------------------------------------------------------------------

void Settings::setMustExportAll(bool exportall)
{
    setValue("git/exportall", exportall);
}

//--------------------------------------------------------------------------------------------------

QSize Settings::uiSize() const
{
    return value("ui/size").toSize();
}

//--------------------------------------------------------------------------------------------------

void Settings::setUiSize(const QSize & size)
{
    setValue("ui/size", size);
}

//--------------------------------------------------------------------------------------------------

QPoint Settings::uiPosition() const
{
    return value("ui/position", QPoint(100,100)).toPoint();
}

//--------------------------------------------------------------------------------------------------

void Settings::setUiPosition(const QPoint & pos)
{
    setValue("ui/position", pos);
}

//--------------------------------------------------------------------------------------------------

QByteArray Settings::uiState() const
{
    return value("ui/state", QByteArray()).toByteArray();
}

//--------------------------------------------------------------------------------------------------

void Settings::setUiState(const QByteArray & state)
{
    setValue("ui/state", state);
}
